package d2_properties;

import java.io.FileReader;
import java.util.Properties;
import java.util.Set;

/**
 * 目标：掌握使用properties类读取属性文件中的信息
 */
public class PropertiesTest1 {
    public static void main(String[] args) throws Exception {
        System.out.println("hello world");
        //1.创建一个Properties的对象出来，(键值对集合，空容器)
        Properties properties = new Properties();
        System.out.println(properties);
        //2.开始加载属性文件中的键值对数据到properties对象中去；
        properties.load(new FileReader("D:\\idea\\idea code\\java-practice\\practice\\properties-xml-log-app\\src\\users.properties"));
        System.out.println(properties);

        //3.根据键取值
        System.out.println(properties.getProperty("hello"));
        System.out.println(properties.getProperty("dance"));

        //4.遍历全部的键和值
        Set<String> keys = properties.stringPropertyNames();
        for (String key : keys) {
            String value = properties.getProperty(key);
            System.out.println(key + "----->" +value);

        }
        //或者用这个方法
        properties.forEach((k,v)->{
            System.out.println(k+"------>" +v);
        });

    }
}
